/*
* Copyright 2005-2008 Pulse Technologies. Tutti i diritti riservati.
*/
package org.obsidianrad.server.web;

import java.io.File;
import java.util.Properties;

import javax.servlet.ServletContext;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 
 * @author eliosh
 * @version $Rev: 4 $
 * @lastautorcommit $Author: eliosh $
 * @lastdatecommit $Date: 2009-10-31 12:37:28 +0100(sab, 31 ott 2009) $
 */
public abstract class WebServer implements ApplicationContextAware {

	protected ApplicationContext applicationContext;
	
	/**
	 * Path sul FS dal quale partire
	 */
	protected File basePath;
	
	/**
	 * Nome host da generare
	 */
	protected String hostName = "localhost";
	
	/**
	 * Path da inserire nel browser
	 */
	protected String contextURI = "";
	
	/**
	 * Nome directory, figlia di <code>basePath</code>, nel quale è presente la 
	 * web application
	 */
	protected String contextPath;
	
	/**
	 * Porta sulla quale attendere per HTTP
	 */
	protected Integer port = 8080;
	
	/**
	 * Porta sulla quale attendere per HTTPS 
	 */
	protected Integer securePort = 8443;
	
	
	/**
	 * Definisce se bisogna attivare anche le connessioni sicure 
	 */
	protected boolean secure=false;
	
	public abstract void startServer() throws Exception;
	public abstract void stopServer() throws Exception;
	public abstract void reloadContext();
	public abstract void init(Properties props);
	public abstract ServletContext getServletContext();
	
	// ----------------- COSTRUTTORI
	public WebServer(File _basePath, String _contextPath, Properties props){
		this.basePath = _basePath;
		this.contextPath = _contextPath;
		init(props);
	}
	public WebServer(String _basePath, String _contextPath, Properties props){
		this(new File(_basePath), _contextPath, props);
	}
	public WebServer(String _basePath, String _contextPath){
		this(new File(_basePath), _contextPath, null);
	}
	public WebServer(File _basePath, String _contextPath){
		this(_basePath, _contextPath, null);
	}
	// ----------------- COSTRUTTORI	
	
	
	public File getBasePath() {
		return basePath;
	}
	public void setBasePath(File basePath) {
		this.basePath = basePath;
	}
	public String getContextPath() {
		return contextPath;
	}
	public void setContextPath(String contextPath) {
		this.contextPath = contextPath;
	}
	public String getContextURI() {
		return contextURI;
	}
	public void setContextURI(String contextURI) {
		this.contextURI = contextURI;
	}
	public String getHostName() {
		return hostName;
	}
	public void setHostName(String hostName) {
		this.hostName = hostName;
	}
	public Integer getPort() {
		return port;
	}
	public void setPort(Integer port) {
		this.port = port;
	}
	public Integer getSecurePort() {
		return securePort;
	}
	public void setSecurePort(Integer securePort) {
		this.securePort = securePort;
	}
	public boolean isSecure() {
		return secure;
	}
	public void setSecure(boolean secure) {
		this.secure = secure;
	}

	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{
		this.applicationContext = applicationContext;
	}
	

	public ApplicationContext getApplicationContext() {
		return this.applicationContext;
	}
}
